package com.xb.service.imp;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xb.entity.Dict;
import com.xb.mapper.DictMapper;
import com.xb.service.IDictService;
import com.xb.util.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * entityService业务层处理
 */
@Service
public class DictServiceImp implements IDictService {
    @Resource
    private DictMapper dictMapper;

    @Override
    public List<String> selectDictByTypeNo(String typeNo) {
        return dictMapper.selectDictByTypeNo(typeNo);
    }

    @Override
    public Result getDict(String typeNo) {
        Result result = new Result();
        result.setData(dictMapper.selectAllDictByTypeNo(typeNo));
        return result;
    }



    /**
     * 分页查询entity列表
     *
     * @param dict entity
     * @return entity
     */
    @Override
    public Result selectDictList(Dict dict, Integer page, Integer limit) {
        Result result = new Result();
        PageHelper.startPage(page, limit);
        List<Dict> list = dictMapper.selectDictList(dict);
        PageInfo<Dict> dictPageInfo = new PageInfo<>(list);
        if (dictPageInfo.getList() != null) {
            result.setData(dictPageInfo.getList());
            result.setStatus(Result.RESPONSE_SUCCESS);
            result.setTotal(dictPageInfo.getTotal());
        }

        return result;
    }

    /**
     * 查询entity列表
     *
     * @param dict entity
     * @return entity
     */
    @Override
    public List<Dict> selectDictList(Dict dict) {
        return dictMapper.selectDictList(dict);
    }

    /**
     * 新增entity
     *
     * @param dict entity
     * @return 结果
     */
    @Override
    public int insertDict(Dict dict) {
        return dictMapper.insertDict(dict);
    }

    /**
     * 修改entity
     *
     * @param dict entity
     * @return 结果
     */
    @Override
    public int updateDict(Dict dict) {
        return dictMapper.updateDict(dict);
    }

    /**
     * 删除entity信息
     *
     * @param id entityID
     * @return 结果
     */
    @Override
    public int deleteDictById(Integer id) {
        return dictMapper.deleteDictById(id);
    }
}
